﻿#include "company.h"
#include <QJsonObject>
#include "tools.h"

Company::Company(QObject *parent) : QObject(parent)
{

}

void Company::loadFromJsonObject(QJsonObject obj)
{
    id = obj.value("id").toInt();
    companyId = obj.value("company_id").toString();
    taxRate = obj.value("tax_rate").toString();
    companyName = obj.value("company_name").toString();
    contact = obj.value("contact").toString();
    tel = obj.value("tel").toString();
    fax = obj.value("fax").toString();
    website = obj.value("website").toString();
    email = obj.value("email").toString();
    province = obj.value("province").toString();
    city = obj.value("city").toString();
    district = obj.value("district").toString();
    address = obj.value("address").toString();
    account = obj.value("account").toString();
    introduction = obj.value("introduction").toString();

    ticketCompanyName = obj.value("ticket_company_name").toString();
    taxNum = obj.value("tax_num").toString();
    bank = obj.value("bank").toString();
    ticketAccount = obj.value("ticket_account").toString();
    ticketTel = obj.value("ticket_tel").toString();
    ticketAddress = obj.value("ticket_address").toString();

    totalTicket = obj.value("total_ticket").toDouble();
    totalMoney = obj.value("total_money").toDouble();
    ticketIn = obj.value("ticket_in").toDouble();
    ticketOut = obj.value("ticket_out").toDouble();
    moneyIn = obj.value("money_in").toDouble();
    moneyOut = obj.value("money_out").toDouble();

    clientCategory = obj.value("client_category").toString();
    giverCategory = obj.value("giver_category").toString();
    productCategory = obj.value("product_category").toString();
    financeCategory = obj.value("finance_category").toString();

//    Tools::cout("id:"+QString("%1").arg(id));
//    Tools::cout("companyId:"+companyId);
//    Tools::cout("taxRate:"+taxRate);
//    Tools::cout("companyName:"+companyName);
//    Tools::cout("contact:"+contact);
//    Tools::cout("tel:"+tel);
//    Tools::cout("fax:"+fax);
//    Tools::cout("website:"+website);
//    Tools::cout("email:"+email);
//    Tools::cout("province:"+province);
//    Tools::cout("city:"+city);
//    Tools::cout("district:"+district);
//    Tools::cout("address:"+address);
//    Tools::cout("account:"+account);
//    Tools::cout("introduction:"+introduction);

//    Tools::cout("ticketCompanyName:"+ticketCompanyName);
//    Tools::cout("taxNum:"+taxNum);
//    Tools::cout("bank:"+bank);
//    Tools::cout("ticketAccount:"+ticketAccount);
//    Tools::cout("ticketTel:"+ticketTel);
//    Tools::cout("ticketAddress:"+ticketAddress);

//    Tools::cout("totalTicket:"+QString("%1").arg(totalTicket));
//    Tools::cout("totalMoney:"+QString("%1").arg(totalMoney));
//    Tools::cout("ticketIn:"+QString("%1").arg(ticketIn));
//    Tools::cout("ticketOut:"+QString("%1").arg(ticketOut));
//    Tools::cout("moneyIn:"+QString("%1").arg(moneyIn));
//    Tools::cout("moneyOut:"+QString("%1").arg(moneyOut));

//    Tools::cout("clientCategory:"+clientCategory);
//    Tools::cout("giverCategory:"+giverCategory);
//    Tools::cout("productCategory:"+productCategory);
//    Tools::cout("financeCategory:"+financeCategory);
}

void Company::saveToSettings()
{
    setCompanyId(companyId);
    setTaxRate(taxRate);

    setCompanyName(companyName);
    setContact(contact);
    setTel(tel);
    setFax(fax);
    setWebsite(website);
    setEmail(email);
    setProvince(province);
    setCity(city);
    setDistrict(district);
    setAddress(address);
    setAccount(account);
    setIntroduction(introduction);

    setTicketCompanyName(ticketCompanyName);
    setTaxNum(taxNum);
    setBank(bank);
    setTicketAccount(ticketAccount);
    setTicketTel(ticketTel);
    setTicketAddress(ticketAddress);

    setTotalTicket(totalTicket);
    setTotalMoney(totalMoney);
    setTicketIn(ticketIn);
    setTicketOut(ticketOut);
    setMoneyIn(moneyIn);
    setMoneyOut(moneyOut);

    setClientCategory(clientCategory);
    setGiverCategory(giverCategory);
    setProductCategory(productCategory);
    setFinanceCategory(financeCategory);
}
